import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.x4ut15m.xwebshell.explorer.controller.FileManagerController;
import org.x4ut15m.xwebshell.sdk.type.ShellType;
import session.WebshellSession;
import webshell.TestWebshellItem;

import java.net.URL;

public class FileManagerRunner extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        TestWebshellItem testWebshellItem = new TestWebshellItem();
        testWebshellItem.setShellType(ShellType.behinder);
        testWebshellItem.setUrl("http://www.baidu.com");
        WebshellSession webshellSession = new WebshellSession(testWebshellItem);
        FXMLLoader fxmlLoader = new FXMLLoader(getTheMainFxml());
        Parent mainScene = fxmlLoader.load();
        FileManagerController fileManagerController = fxmlLoader.getController();
        fileManagerController.setBelongToStage(primaryStage);
        fileManagerController.setWebshellItem(testWebshellItem);
        fileManagerController.setWebshellSession(webshellSession);
        fileManagerController.loadAllSubModule();
        fileManagerController.createEventHandlerOnComponents();
        primaryStage.setScene(new Scene(mainScene));
        primaryStage.setTitle("X-Webshell-File-Explorer test 0.0.1");
        primaryStage.show();
    }

    public URL getTheMainFxml() {
        return this.getClass().getResource("/FileManageTab-test.fxml");
    }
}
